package com.founder.bdyx.task;

import com.founder.bdyx.wxpay.mapper.PayNoticeInfoMapper;
import com.founder.bdyx.wxpay.model.PayNoticeInfo;
import com.founder.bdyx.wxpay.service.WxPayV3Service;
import com.founder.bdyx.wxpro.conf.WxConfig;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 请求分账
 */
@Component
public class ProfitSharingTask implements Job {
    Logger log = LoggerFactory.getLogger(ProfitSharingTask.class);

    @Autowired
    private WxConfig wxConfig;
    @Autowired
    private PayNoticeInfoMapper payNoticeInfoMapper;
    @Autowired
    WxPayV3Service wxPayV3Service;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        log.info("请求分账任务执行。。");

        List<PayNoticeInfo> notList = payNoticeInfoMapper.getAllToShare("NOT");

        for (PayNoticeInfo info :
                notList) {
            wxPayV3Service.profitShareRequest(info);
        }

        List<PayNoticeInfo> processList = payNoticeInfoMapper.getAllToShare("PROCESSING");

        for (PayNoticeInfo info :
                processList) {
            wxPayV3Service.profitShareResult(info);
        }

        List<PayNoticeInfo> finishList = payNoticeInfoMapper.getAllToShare("FINISHED");

        for (PayNoticeInfo info :
                finishList) {
            wxPayV3Service.profitShareUnfreeze(info);
        }
    }
}
